<?php

namespace app\api\controller;

use app\common\controller\Api;
use function fast\array_except;

/**
 * 首页接口
 */
class Data extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $mhotel = "";

    public function __construct(){
        parent::__construct();
        $this->mainhost = "http://".$_SERVER["HTTP_HOST"];
    }

    //获取自动轮播时间
    public function getset(){
        //获取全局配置的条数
        $looptimecof = model('Config')->where("name='looptime'")->field("value")->find();
        if($looptimecof){
            $looptimecof = $looptimecof->toarray()["value"];
            $looptimecof = json_decode($looptimecof,true);
        }
        if($looptimecof){
            $time = $looptimecof;
        }else{
            $time = 3000;
        }

        //获取办公室的信息
        $baseset = model('Config')->where("name='baseset'")->field("value")->find();

        if($baseset){
            $baseset = $baseset->toarray()["value"];
            $baseset = json_decode($baseset,true);
        }

//        $str = '['.$baseset['经度'].','.$baseset['纬度'].']';
//        $array=array(
//            $baseset['办公室']=>$str
//        );

        $res['baseset'] = $baseset;
        $res['looptime'] = $time;


        $res['res'] = array(
            '长兴岛联办'=>['121.66603088378906','31.41079122733506'],
            '上边的小点'=>['121.60938262939453','31.460003942647035'],
            '右边的小点'=>['121.74980163574219','31.36507058051698'],


        );


        $this->success("success",$res);

    }

    // 项目清单 列表
    public function proitems()
    {

        $mid = $this->request->request("mid");//一级板块id
        $sid = $this->request->request("sid");//建设单位
        $pid = $this->request->request("pid");//资金来源
        if($mid){
            $resdata = db("project")->where(['unit_id'=>$mid])->field("id,number as pcode,unit_id,a_id,p_id,title as projectname,subject,lng as plong,lat as plat")->select();
        }elseif ($sid){
            $resdata = db("project")->where(['subject'=>$sid])->field("id,number as pcode,unit_id,a_id,p_id,title as projectname,subject,lng as plong,lat as plat")->select();
        }elseif ($pid){
            $resdata = db("project")->where(['p_id'=>$pid])->field("id,number as pcode,unit_id,a_id,p_id,title as projectname,subject,lng as plong,lat as plat")->select();
        }else{
            $resdata = db("project")->field("id,number as pcode,unit_id,a_id,p_id,title as projectname,subject,lng as plong,lat as plat")->select();
        }



        if($resdata){
            $this->success("success",$resdata);
        }else{
            $this->success("暂无数据",[]);
        }

    }

    // 项目清单 列表
    public function proitemsold()
    {
        //获取全局配置的条数
        $limitcof = model('Config')->where("name='pagesize'")->field("value")->find();
        if($limitcof){
            $limitcof = $limitcof->toarray()["value"];
            $limitcof = json_decode($limitcof,true);
        }
        if($limitcof){
            $limit = $limitcof;
        }else{
            $limit = 10;
        }

        $list = db("projectlist")->where(['type'=>'new','hot'=>1])->field("id,pid,projectname")->order("hot desc,id asc")->select();

        $dbpro = db("project");
        $dbbld = db("build");
        $dbsta = db("stage");
        $res = [];
        if($list){
            foreach ($list as $v){
                //如果建设单位状态停业 全站关于该 建设单位的项目数据则都不显示 只后台数据保留
                //项目信息
                $pinfo = $pro = $dbpro->where(['id'=>$v['pid']])->find();
                $v['pcode'] = $pinfo['p_code'];
                $v['plong'] = $pinfo['p_long'];
                $v['plat'] = $pinfo['p_lat'];
                //建设单位
                $binfo = $dbbld->where(['id'=>$pinfo['p_bid']])->find();
                $v['pbname'] = $binfo['b_name'];
                $status = $binfo['status'];
                //当前阶段
                $sinfo = $dbsta->where(['id'=>$pinfo['p_sid']])->find();
                $v['psname'] = $sinfo['s_name'];
                $v['psid'] = $sinfo['id'];
                if($status == 0){
                    //建设单位 正常
                    array_push($res,$v);
                }

            }

            //截取数组个数
            $count = count($res);
            if($count > $limit){
                $resdata = array_slice($res,0,$limit);
            }else{
                $resdata = $res;
            }

            $this->success("success",$resdata);
        }else{
            $this->success("暂无数据",[]);
        }

    }

    //初始化返回项目数据 地图下 统计
    protected function initem($pcid){
        if($pcid == "all"){
            //项目总数
            $allpro = db("project")->count();
            $res['allpro'] = $allpro;
            //已完成的
            $donepro = db("project")->where(['p_sid'=>4])->count();
            $res['donepro'] = $donepro;
            //正在进行 = 总-完成的
            $res['doingpro'] = $allpro - $donepro;
            //预警 逻辑待定 先写死 1
            $res['prepro'] = 1;

        }else{
            //项目总数
            $allpro = db("project")->where(['p_cid'=>$pcid])->count();
            $res['allpro'] = $allpro;
            //已完成的
            $donepro = db("project")->where(['p_cid'=>$pcid])->where(['p_sid'=>4])->count();
            $res['donepro'] = $donepro;
            //正在进行 = 总-完成的
            $res['doingpro'] = $allpro - $donepro;
            //预警 逻辑待定 先写死 1
            $res['prepro'] = 1;
        }

        return $res;


    }

    //项目清单统计 3个饼图 一级项目板块 建设主体（不能超过10个）  资金来源
    //一级项目板块 第一个饼图
    public function probitem(){
        //项目板块
        $bdb = db("ministries");
        $pdb = db("project");
        $list = $bdb->field("m_name,id")->select();
        if($list){
            $baarr = [];
            foreach ($list as $v){
                $bcount = $pdb->where(['unit_id'=>$v['id']])->count();
                $barr['name'] = $v['m_name'];
                $barr['y'] = $bcount;
                $barr['sliced'] = false;
                $barr['selected'] = false;
                $barr['bid'] = $v['id'];
                array_push($baarr,$barr);
            }

            //$bjson = json_encode($baarr);
            //项目板块
            $res['bjson'] = $baarr;

            $this->success("success",$res);


        }else{
            $this->error("项目板块数据有误");
        }

    }
    //建设主体 第二个饼图 最多不能超过10个扇形
    public function prositem(){


        //建设单位
        $sdb = db("subject");
        $pdb = db("project");
        $list = $sdb->field("subject,id")->select();
        if($list){
            $baarr = [];
            foreach ($list as $v){
                $bcount = $pdb->where(['subject'=>$v['id']])->count();
                $barr['name'] = $v['subject'];
                $barr['y'] = $bcount;
                $barr['sliced'] = false;
                $barr['selected'] = false;
                $barr['sid'] = $v['id'];
                array_push($baarr,$barr);
            }

            //二维数组指定键排序，降序
            $baarr  = array_sort($baarr,'y','desc');
            $len = count($baarr);
            //判断数组是否大于10
            if($len <= 10){
                //建设主体
                $res['sjson'] = $baarr;
                $this->success("success",$res);
            }else{
                //取出前9个数据 第10个以后的数据 变成 “其他”显示
                $newarr = [];
                $oldids = "";
                foreach ($baarr as $kk=>$vv){
                    if($kk <9){
                        $newarr[] = $vv;
                        $oldids .= ",".$vv['sid'];
                    }
                }

                $oldids = ltrim($oldids,",");

                //取出其他 的 id 信息
                $qtids = $sdb->field('id')->where("id not in ($oldids)")->select();
                $qtidsstr = '';
                $qtarr = [];
                if($qtids){
                    foreach ($qtids as $kkk=>$vvv){
                            //  $qtidsstr .= ",".$vvv['id'];
                             array_push($qtarr,$vvv['id']);
                    }
                }



                //获取剩下的数据个数
                $qcount = $pdb->where("subject not in ($oldids)")->count();
                $qt['name'] = "其他";
                $qt['y'] = $qcount;
                $qt['sliced'] = false;
                $qt['selected'] = false;
                $qt['sid'] = $qtarr;

                array_push($newarr,$qt);

                //建设主体
                $res['sjson'] = $newarr;
                $this->success("success",$res);
            }

        }else{
            $this->error("建设主体数据有误");
        }

    }

    //资金来源 第三个饼图
    /*{name: '旅游',y: 2,sliced: false,selected: false},
    {name: '土建',y: 3,sliced: false,selected: false},
    {name: '农业',y: 4,sliced: false,selected: false},
    {name: '基建',y: 5,sliced: false,selected: false},*/
    public function propitem(){


        $model = model("project");
        //转移支付
        $pcount = $model
            ->join("payment p", 'fa_project.p_id = p.id')
            ->where("p.payment !=0")
            ->count();
        //自筹
        $ecount = $model
            ->join("payment p", 'fa_project.p_id = p.id')
            ->where("p.expense !=0")
            ->count();
        //市府配比
       /* $rcount = $model
            ->join("payment p", 'fa_project.p_id = p.id')
            ->where("p.ratio=1")
            ->count();*/
        //其他
        $ocount = $model
            ->join("payment p", 'fa_project.p_id = p.id')
            ->where("p.other !=0")
            ->count();

        $baarr = [];
        $barr['name'] = "转移支付";
        $barr['y'] = $pcount;
        $barr['sliced'] = false;
        $barr['selected'] = false;
        $barr['pid'] = 1;
        array_push($baarr,$barr);
        $barr['name'] = "自费";
        $barr['y'] = $ecount;
        $barr['sliced'] = false;
        $barr['selected'] = false;
        $barr['pid'] = 2;
        array_push($baarr,$barr);
        $barr['name'] = "市府配比";
        /*$barr['y'] = $rcount;
        $barr['sliced'] = false;
        $barr['selected'] = false;
        $barr['pid'] = 3;
        array_push($baarr,$barr);*/
        $barr['name'] = "其他";
        $barr['y'] = $ocount;
        $barr['sliced'] = false;
        $barr['selected'] = false;
        $barr['pid'] = 4;
        array_push($baarr,$barr);

        $res['pjson'] = $baarr;

        $this->success("success",$res);


    }

    //项目清单统计 饼图
    public function procitemold(){
        //项目总数 就是 7打板块
        $resdata = [];
        $list = db("category")->field('id,name,bkflag')->where(['pid'=>0])->select();
        $list2 = db("project")->count();
        $resdata['allpro'] = count($list);
        $resdata['itempro'] = $list2;
        $resdata['alldata'] = $this->initem("all");
        $blist = db("category")->field('id,name,pid')->select();
        $looptimecof = model('Config')->where("name='looptime'")->field("value")->find();
        if($looptimecof){
            $looptimecof = $looptimecof->toarray()["value"];
            $looptimecof = json_decode($looptimecof,true);
        }
        if($looptimecof){
            $time = $looptimecof;
        }else{
            $time = 3000;
        }

        foreach ($list as $v){
            $bkdata = getUpTree($blist,$v['id']);
            $str = implode(",",$bkdata);
            $info = db("project")->where("p_cid in ($str)")->count();
            $resdata['pro'.$v['bkflag']]['value'] = $info;
            $resdata['pro'.$v['bkflag']]['title'] = $v['name'];
            //局部板块统计
            $resdata['pro'.$v['bkflag']]['data'] = $this->initem($v['id']);
            $resdata['loptime'] = $time;
            $res = array($info,$v['name']);
            $resdata['res'][] = $res;

            $resdata['respro'][] = $this->initem($v['id']);

        }

        $this->success("success",$resdata);


    }

    //项目专家库
    public function professor(){
        $proid = $this->request->request("proid");//项目id
        if($proid){
            //项目关联专家
            $list = db("professor")->where(['status'=>'normal'])->where("FIND_IN_SET($proid,`proids`)")->order("id desc")->select();
        }else{
            //全部专家
            $list = db("professor")->where(['status'=>'normal'])->order("id desc")->select();
        }

        $host = "http://".$_SERVER['HTTP_HOST'];
        if($list){
            foreach ($list as &$v){
                $v['img'] = $host.$v['img'];
                $v['intro2'] = subText3($v['intro'],110);
            }
            $this->success("success",$list);
        }else{
            $this->success("success",[]);
        }
    }



    //大事件
    public function news(){
        $proid = $this->request->request("proid");//项目id
        if($proid){
            //项目相关的大事记
            $list = db("news")->field("id,name as title,content as detail,time as date")->where(['status'=>'normal'])->where("FIND_IN_SET($proid,`proids`)")->order("time asc")->select();
        }else{
            //全部大事记
            $list = db("news")->field("id,name as title,content as detail,time as date")->where(['status'=>'normal'])->order("time asc")->select();
        }


        if($list){
            $this->success("success",$list);
        }else{
            $this->success("success",[]);
        }


    }

    //项目数据统计 地图
    public function mappro0704(){

        $mid = $this->request->request("bid");//一级板块id
        $sid = $this->request->request("sid");//建设单位
        $pid = $this->request->request("pid");//资金来源


        //获取办公室的信息
        $baseset = model('Config')->where("name='baseset'")->field("value")->find();
        if($baseset){
            $baseset = $baseset->toarray()["value"];
            $baseset = json_decode($baseset,true);
        }

        $res = [];

        $res['res'][$baseset['办公室']]  = [$baseset['经度'],$baseset['纬度']];

        //统计初始化数据
        $countdata["allcount"] = 0;
        $countdata["doingcount"] = 0;
        $countdata["donecount"] = 0;
        $countdata["predoigcount"] = 0;



        if($mid){
            //获取真实数据
            $list = db("project")->where(['unit_id'=>$mid])->field("id,title as p_name,number as p_code,unit_id as p_cid,lng as p_long,lat as p_lat,color,size")->select();
            //左侧数据
            $resdata = db("project")->where(['unit_id'=>$mid])->field("id,number as pcode,unit_id,a_id,p_id,title as projectname,subject,lng as plong,lat as plat")->select();
            //右侧统计数据
            //项目总数
            $allcount = db("project")->where(['unit_id'=>$mid])->count();
            //正在进行
            $doingcount = db("project")->where(['unit_id'=>$mid,'status'=>'0'])->count();
            //已完成
            $donecount = db("project")->where(['unit_id'=>$mid,'status'=>'3'])->count();
            //滞后、预警
            $predoigcount = db("project")->where(['unit_id'=>$mid,'status'=>'2'])->count();
            $countdata["allcount"] = $allcount;
            $countdata["doingcount"] = $doingcount;
            $countdata["donecount"] = $donecount;
            $countdata["predoigcount"] = $predoigcount;


        }elseif ($sid){
            //获取真实数据
            $list = db("project")->where(['subject'=>$sid])->field("id,title as p_name,number as p_code,unit_id as p_cid,lng as p_long,lat as p_lat,color,size")->select();
            $resdata = db("project")->where(['subject'=>$sid])->field("id,number as pcode,unit_id,a_id,p_id,title as projectname,subject,lng as plong,lat as plat")->select();
            //右侧统计数据
            //项目总数
            $allcount = db("project")->where(['subject'=>$sid])->count();
            //正在进行
            $doingcount = db("project")->where(['subject'=>$sid,'status'=>'0'])->count();
            //已完成
            $donecount = db("project")->where(['subject'=>$sid,'status'=>'3'])->count();
            //滞后、预警
            $predoigcount = db("project")->where(['subject'=>$sid,'status'=>'2'])->count();
            $countdata["allcount"] = $allcount;
            $countdata["doingcount"] = $doingcount;
            $countdata["donecount"] = $donecount;
            $countdata["predoigcount"] = $predoigcount;

        }elseif ($pid){

            //pid = 1 转移支付 2 自费 3 市府配比 4 其他

            if($pid == 1){
                $where['payment'] = 1;
            }elseif ($pid == 2){
                $where['expense'] = 1;
            }elseif ($pid == 3){
                $where['ratio'] = 1;
            }else{
                $where['other'] = 1;
            }

            $plist = db("payment")->where($where)->field("id")->select();
            $pstr = "";
            if($plist){
                foreach ($plist as $v){
                    $pstr .= ",".$v['id'];
                }
            }

            if($pstr != ""){
                $pstr = ltrim($pstr,",");
                //获取真实数据
                $list = db("project")->where("p_id in ($pstr)")->field("id,p_id,title as p_name,number as p_code,unit_id as p_cid,lng as p_long,lat as p_lat,color,size")->select();
                $resdata = db("project")->where("p_id in ($pstr)")->field("id,number as pcode,unit_id,a_id,p_id,title as projectname,subject,lng as plong,lat as plat")->select();
                //右侧统计数据
                //项目总数
                $allcount = db("project")->where("p_id in ($pstr)")->count();
                //正在进行
                $doingcount = db("project")->where("p_id in ($pstr)")->where(['status'=>'0'])->count();
                //已完成
                $donecount = db("project")->where("p_id in ($pstr)")->where(['status'=>'3'])->count();
                //滞后、预警
                $predoigcount = db("project")->where("p_id in ($pstr)")->where(['status'=>'2'])->count();
                $countdata["allcount"] = $allcount;
                $countdata["doingcount"] = $doingcount;
                $countdata["donecount"] = $donecount;
                $countdata["predoigcount"] = $predoigcount;

            }


        }else{
            //获取真实数据
            $list = db("project")->field("id,title as p_name,number as p_code,unit_id as p_cid,lng as p_long,lat as p_lat,color,size")->select();
            $resdata = db("project")->field("id,number as pcode,unit_id,a_id,p_id,title as projectname,subject,lng as plong,lat as plat")->select();
            //右侧统计数据
            //项目总数
            $allcount = db("project")->count();
            //正在进行
            $doingcount = db("project")->where(['status'=>'0'])->count();
            //已完成
            $donecount = db("project")->where(['status'=>'3'])->count();
            //滞后、预警
            $predoigcount = db("project")->where(['status'=>'2'])->count();
            $countdata["allcount"] = $allcount;
            $countdata["doingcount"] = $doingcount;
            $countdata["donecount"] = $donecount;
            $countdata["predoigcount"] = $predoigcount;
        }





        $res['name'] = [];
        $res['size'] = [];
        $res['color'] = [];


        if($list){

            foreach ($list as $vv){
                //如果经纬度都为空 则返回
                if($vv['p_long'] && $vv['p_lat']){
                    $res['res'][$vv['p_name']] = [$vv['p_long'],$vv['p_lat']];
                    $res['name'][]=$vv['p_name'];
                    $res['size'][]=$vv['size'];
                    $res['color'][]=$vv['color'];
                }

            }
        }

        //追加长兴岛数据
        array_unshift($res['name'],  $baseset['办公室']);
        array_unshift($res['size'],  (int)$baseset['大小']);
        array_unshift($res['color'],  $baseset['颜色']);
        $res['dadian']=$baseset['办公室'];
        //左侧清单数据
        if($resdata){
            $res['itemlist'] = $resdata;
        }else{
            $res['itemlist'] = [];
        }

        //数据统计
        $res['itemcount'] = $countdata;

        $this->success("success",$res);

    }


    public function getItem(){
        $name = $this->request->request("name");//一级板块id

        $area1 = substr($name,0,4);
        $code = substr($name,4);


        if($area1 == "zhzg"){
            $area = 1;
        }elseif($area1 == 'zhcx'){
            $area = 2;
        }elseif($area1 == 'jnzz'){
            $area = 3;
        }else{
            $area = 4;
        }



        $list = db("project")->where(['area'=>$area,'areacode'=>$code])->field('id,title,area,areacode')->select();

        if($list){
            $this->success("success",$list);
        }else{
            $this->success("success",[]);
        }


    }

    //项目数据统计 地图 锚点 方式
    public function mappro(){


        $mid = $this->request->request("bid");//一级板块id
        $sid = $this->request->request("sid");//建设单位
        $pid = $this->request->request("pid");//资金来源
        $id = $this->request->request("id");//点击地图锚点 返回对应数据

        $imglist = ['A1','A2','A3','A4','A5','A6','A7','A8','A9','A10','A11','A12','A13','A14','A15','A16','A17','A18','A19','A20','A21','A22','A23'];
        $list = [];
        $resdata = [];
        $res = [];
        //统计初始化数据
        $countdata["allcount"] = 0;
        $countdata["doingcount"] = 0;
        $countdata["donecount"] = 0;
        $countdata["predoigcount"] = 0;

        $imageslist = ['http://cxd.shaomingkeji.cn/uploads/test/1.jpg','http://cxd.shaomingkeji.cn/uploads/test/2.jpg'];//图片数组
        $videolist = ['http://cxd.shaomingkeji.cn/uploads/test/xmjs.mp4','http://cxd.shaomingkeji.cn/uploads/test/test.mp4'];//视频数组


        //点击锚点 返回相关数据
        if($id){
            $imglist = [];
            $list = db("project")->where(['areacode'=>$id])->field("id,title as p_name,number as p_code,unit_id as p_cid,area,areacode")->select();


            //左侧数据
            $resdata = db("project")->where(['areacode'=>$id])->field("id,number as pcode,unit_id,a_id,p_id,title as projectname,subject,areacode")->select();
            //右侧统计数据
            //项目总数
            $allcount = db("project")->where(['areacode'=>$id])->count();
            //正在进行
            $doingcount = db("project")->where(['areacode'=>$id,'status'=>'0'])->count();
            //已完成 包括已完成和超前的数据 status
            $donecount = db("project")->where(['areacode'=>$id])->where("status=3 || status = 1")->count();
            //$donecount = db("project")->where(['areacode'=>$id,'status'=>'3'])->count();
            //滞后、预警
            $predoigcount = db("project")->where(['areacode'=>$id,'status'=>'2'])->count();
            $countdata["allcount"] = $allcount;
            $countdata["doingcount"] = $doingcount;
            $countdata["donecount"] = $donecount;
            $countdata["predoigcount"] = $predoigcount;


        }elseif($mid){
            $imglist = [];
            //获取真实数据
            $imageslist = ['http://cxd.shaomingkeji.cn/uploads/test/3.jpg','http://cxd.shaomingkeji.cn/uploads/test/4.png'];
            $videolist = ['http://cxd.shaomingkeji.cn/uploads/test/test2.mp4','http://cxd.shaomingkeji.cn/uploads/test/video2.mp4'];

            $list = db("project")->where(['unit_id'=>$mid])->field("id,title as p_name,number as p_code,unit_id as p_cid,area,areacode")->select();


            //左侧数据
            $resdata = db("project")->where(['unit_id'=>$mid])->field("id,number as pcode,unit_id,a_id,p_id,title as projectname,subject,areacode")->select();
            //右侧统计数据
            //项目总数
            $allcount = db("project")->where(['unit_id'=>$mid])->count();
            //正在进行
            $doingcount = db("project")->where(['unit_id'=>$mid,'status'=>'0'])->count();
            //已完成
            //$donecount = db("project")->where(['unit_id'=>$mid,'status'=>'3'])->count();
            //已完成 包括已完成和超前的数据 status
            $donecount = db("project")->where(['unit_id'=>$mid])->where("status=3 || status = 1")->count();
            //滞后、预警
            $predoigcount = db("project")->where(['unit_id'=>$mid,'status'=>'2'])->count();
            $countdata["allcount"] = $allcount;
            $countdata["doingcount"] = $doingcount;
            $countdata["donecount"] = $donecount;
            $countdata["predoigcount"] = $predoigcount;


        }elseif ($sid){
            $imglist = [];
            //获取真实数据
            $list = db("project")->where("subject in ($sid)")->field("id,title as p_name,number as p_code,unit_id as p_cid,area,areacode")->select();

            $resdata = db("project")->where("subject in ($sid)")->field("id,number as pcode,unit_id,a_id,p_id,title as projectname,subject,areacode")->select();
            //右侧统计数据
            //项目总数
            $allcount = db("project")->where("subject in ($sid)")->count();
            //正在进行
            $doingcount = db("project")->where("subject in ($sid)")->where(['status'=>'0'])->count();
            //已完成
            //$donecount = db("project")->where("subject in ($sid)")->where(['status'=>'3'])->count();
            //已完成 包括已完成和超前的数据 status
            $donecount = db("project")->where("subject in ($sid)")->where("status=3 || status = 1")->count();
            //滞后、预警
            $predoigcount = db("project")->where("subject in ($sid)")->where(['status'=>'2'])->count();
            $countdata["allcount"] = $allcount;
            $countdata["doingcount"] = $doingcount;
            $countdata["donecount"] = $donecount;
            $countdata["predoigcount"] = $predoigcount;

        }elseif ($pid){
            $imglist = [];

            //pid = 1 转移支付 2 自费 3 市府配比 4 其他

            if($pid == 1){
                //$where['payment'] = 1;
                $where = "payment != 0";
            }elseif ($pid == 2){
                //$where['expense'] = 1;
                $where = "expense != 0";
            }elseif ($pid == 3){
               // $where['ratio'] = 1;
                $where = "ratio != 0";
            }else{
                //$where['other'] = 1;
                $where = "other != 0";
            }

            $plist = db("payment")->where($where)->field("id")->select();
            $pstr = "";
            if($plist){
                foreach ($plist as $v){
                    $pstr .= ",".$v['id'];
                }
            }

            if($pstr != ""){
                $pstr = ltrim($pstr,",");
                //获取真实数据
                $list = db("project")->where("p_id in ($pstr)")->field("id,p_id,title as p_name,number as p_code,unit_id as p_cid,area,areacode")->select();

                $resdata = db("project")->where("p_id in ($pstr)")->field("id,number as pcode,unit_id,a_id,p_id,title as projectname,subject,areacode")->select();
                //右侧统计数据
                //项目总数
                $allcount = db("project")->where("p_id in ($pstr)")->count();
                //正在进行
                $doingcount = db("project")->where("p_id in ($pstr)")->where(['status'=>'0'])->count();
                //已完成
                //$donecount = db("project")->where("p_id in ($pstr)")->where(['status'=>'3'])->count();
                //已完成 包括已完成和超前的数据 status
                $donecount = db("project")->where("p_id in ($pstr)")->where("status=3 || status = 1")->count();
                //滞后、预警
                $predoigcount = db("project")->where("p_id in ($pstr)")->where(['status'=>'2'])->count();
                $countdata["allcount"] = $allcount;
                $countdata["doingcount"] = $doingcount;
                $countdata["donecount"] = $donecount;
                $countdata["predoigcount"] = $predoigcount;

            }


        }else{
            //获取真实数据
            $list = db("project")->field("id,title as p_name,number as p_code,unit_id as p_cid,area,areacode")->select();

            $resdata = db("project")->field("id,number as pcode,unit_id,a_id,p_id,title as projectname,subject,areacode")->select();
            //右侧统计数据
            //项目总数
            $allcount = db("project")->count();
            //正在进行
            $doingcount = db("project")->where(['status'=>'0'])->count();
            //已完成
            //$donecount = db("project")->where(['status'=>'3'])->count();
            //已完成 包括已完成和超前的数据 status
            $donecount = db("project")->where("status=3 || status = 1")->count();
            //滞后、预警
            $predoigcount = db("project")->where(['status'=>'2'])->count();
            $countdata["allcount"] = $allcount;
            $countdata["doingcount"] = $doingcount;
            $countdata["donecount"] = $donecount;
            $countdata["predoigcount"] = $predoigcount;
        }



        if($list){
            foreach ($list as $vv){

                if($vv['areacode'] != ''){
                    if(!in_array($vv['areacode'],$imglist)){
                        array_push($imglist,$vv['areacode']);
                    }
                }
            }
        }



        //左侧清单数据
        if($resdata){
            foreach ($resdata as &$v3){
                $v3['smalltitle'] = subText3($v3['projectname'],8);
            }
            $res['itemlist'] = $resdata;
        }else{
            $res['itemlist'] = [];
        }

        //数据统计
        $res['itemcount'] = $countdata;



        //控制哪些锚点点显示
        $res['imglist'] = $imglist;


        //控制哪些图片显示
        $res['imageslist'] = $imageslist;
        //控制哪些视频显示
        $res['videolist'] = $videolist;

        $this->success("success",$res);

    }


    //项目数据统计 地图
    public function mapproold(){
        //获取办公室的信息
        $baseset = model('Config')->where("name='baseset'")->field("value")->find();

        if($baseset){
            $baseset = $baseset->toarray()["value"];
            $baseset = json_decode($baseset,true);
        }

        $res['res'][$baseset['办公室']]  = [$baseset['经度'],$baseset['纬度']];

        //获取真实数据
        $list = db("project")->field("id,p_name,p_code,p_cid,p_long,p_lat,color,size")->select();
        foreach ($list as $vv){
            //如果经纬度都为空 则返回
            if($vv['p_long'] && $vv['p_lat']){
                $res['res'][$vv['p_name']] = [$vv['p_long'],$vv['p_lat']];
                $res['name'][]=$vv['p_name'];
                $res['size'][]=$vv['size'];
                $res['color'][]=$vv['color'];
            }

        }

        $res['dadian']=$baseset['办公室'];

        /*
                $k2 = 100;

                foreach ($res['name'] as $k => $v){
                    $res['size'][]=$k2;
                    $k2 = $k2+20;
                    $res['color'][]='red';
                }

                $res['color'][0]='red';
                $res['color'][1]='blue';
                $res['color'][2]='yellow';
                $res['color'][3]='orange';
                $res['color'][4]='green';
                $res['color'][5]='grey';
                $res['color'][6]='black';
                $res['color'][7]='pink';

        */

        $this->success("success",$res);

    }

    //首页地图下 统计数据 暂定逻辑 点击饼图或者表格 动态 筛选 对应板块下数据
    public function dataitem(){
        $p_cid = $this->request->request("pcid");//板块id
        if($p_cid){
            //项目总数
            $allpro = db("project")->where(['p_cid'=>$p_cid])->count();
            $res['allpro'] = $allpro;
            //已完成的
            $donepro = db("project")->where(['p_cid'=>$p_cid])->where(['p_sid'=>4])->count();
            $res['donepro'] = $donepro;
            //正在进行 = 总-完成的
            $res['doingpro'] = $allpro - $donepro;
            //预警 逻辑待定 先写死 1
            $res['prepro'] = 1;
        }else{
            //项目总数
            $allpro = db("project")->count();
            $res['allpro'] = $allpro;
            //已完成的
            $donepro = db("project")->where(['p_sid'=>4])->count();
            $res['donepro'] = $donepro;
            //正在进行 = 总-完成的
            $res['doingpro'] = $allpro - $donepro;
            //预警 逻辑待定 先写死 1
            $res['prepro'] = 1;
        }

        $this->success("success",$res);

    }

    //单个汇报详情
    public function oneproold(){
        $proid = $this->request->request("proid");
        $info = db("projectlist")->field("id,pid,work,workfrom,projectname,probasic,promeaning,procontent,prosum,imgs,vedios,probody,remark")->where(['id'=>$proid])->find();
        //处理图片
        if($info['imgs']){
            $imgs = explode(",", $info['imgs']);
            $host = "http://".$_SERVER['HTTP_HOST'];
            foreach ($imgs as &$v){
                $v = $host.$v;
            }
            $info['imgs'] = $imgs;
        }
        if($info){
            $this->success("success",$info);
        }else{
            $this->error("数据错误");
        }


    }

    //单个汇报详情
    public function onepro(){
        $proid = $this->request->request("proid");
        $info = db("project")->where(['id'=>$proid])->find();

        if($info){
            //任务来源处理
            //$info['proof'] = explode("##",$info['proof']);
            //获取单个最新汇报
            $hbdata = db("projectlist")->where(['pid'=>$proid,'type'=>1])->find();

            if($hbdata){
                //处理图片
                if(!empty($hbdata['imgs'])){
                    $imglist = explode(",",$hbdata['imgs']);
                    foreach ($imglist as &$v){
                        $v = $this->mainhost.$v;
                    }
                    unset($hbdata['imgs']);
                    $hbdata['imglist'] = $imglist;
                }else{
                    //本次汇报没有图片，则显示最近的有图片数据的图片
                    $hbdataold = db("projectlist")->where(['pid'=>$proid,'type'=>0])->where("imgs !=''")->order("id desc")->find();
                    if($hbdataold){
                        $imglist = explode(",",$hbdataold['imgs']);
                        foreach ($imglist as &$v){
                            $v = $this->mainhost.$v;
                        }
                        unset($hbdata['imgs']);
                        $hbdata['imglist'] = $imglist;
                    }else{
                        $hbdata['imglist'] = "";
                    }
                }
                //处理视频
                if(!empty($hbdata['vedios'])){
                    $vedios = explode(",",$hbdata['vedios']);
                    foreach ($vedios as &$v){
                        $v = $this->mainhost.$v;
                    }
                    unset($hbdata['vedios']);
                    $hbdata['vediolist'] = $vedios;
                }else{
                    //本次汇报没有图片，则显示最近的有图片数据的图片
                    $hbdataold = db("projectlist")->where(['pid'=>$proid,'type'=>0])->where("vedios !=''")->order("id desc")->find();
                    if($hbdataold){
                        $vedios = explode(",",$hbdataold['vedios']);
                        foreach ($vedios as &$v){
                            $v = $this->mainhost.$v;
                        }
                        unset($hbdata['vedios']);
                        $hbdata['vediolist'] = $vedios;
                    }else{
                        $hbdata['vediolist'] = "";
                    }
                }

                $info['newhbdata'] = $hbdata;
            }else{
                $info['newhbdata'] = "";
            }
            $this->success("success",$info);
        }else{
            $this->error("数据错误");
        }
    }


    //动态计算年度汇报比例
    public function testPercent(){
        $sdate = "2022-03";
        $edate = "2022-10";
        //comPercent($sdate,$edate);
        comhbdate($sdate,$edate);
    }





}
